clear

do "sfa0809.do"

do "ic2009_ay.do"

do "ef2009a.do"

merge 1:1 unitid using "sfa0809_small.dta"
rename _merge mergeaid
merge 1:1 unitid using "ic2009_ay_small.dta"
rename _merge mergetuition
save "price.dta", replace

clear
use "degenrollempstaff_inst_8018.dta"

keep if year==2009
merge 1:1 unitid using "price.dta"
rename _merge mergepricefull
drop if mergepricefull==2

egen avggrantschaidall = rowmax(gis4a2 grn4a2)

egen avgaid030 = rowmax(gis4a12 grn4a12)
egen avgaid3048 = rowmax(gis4a22 grn4a22)
egen avgaid4875 = rowmax(gis4a32 grn4a32)
egen avgaid75110 = rowmax(gis4a42 grn4a42)
egen avgaid110pl = rowmax(gis4a52 grn4a52)

egen avgnetpriceall = rowmax(npist2 npgrn2)

egen avgnp030 = rowmax(npis412 npt412)
egen avgnp3048 = rowmax(npis422 npt422)
egen avgnp4875 = rowmax(npis432 npt432)
egen avgnp75110 = rowmax(npis442 npt442)
egen avgnp110pl = rowmax(npis452 npt452)

egen tuitandfee = rowtotal(tuition2 fee2), missing


preserve
keep if four_yr==1 & tuitandfee~=.

su public avggrantschaidall avgaid030 avgaid3048 avgaid4875 avgaid75110 avgaid110pl avgnetpriceall avgnp030 avgnp3048 avgnp4875 avgnp75110 avgnp110pl tuitandfee  scugffn
keep if tuitandfee~=. & avgnetpriceall~=. & avggrantschaidall~=. & avgaid030~=. & avgaid3048~=. & avgnp030~=. & avgnp3048~=. & scugffn~=.

count

collapse avggrantschaidall avgaid030 avgaid3048 avgnetpriceall avgnp030 avgnp3048 tuitandfee [aw=scugffn], by(cty_fips)
merge 1:1 cty_fips using "justnormasylum.dta"
rename _merge mergenorm
keep if mergenorm==3

tostring cty_fips, gen(cty_fipstr)
gen statefip = substr(cty_fipstr, 1,1) if length(cty_fipstr)==4
replace statefip = substr(cty_fipstr, 1, 2) if length(cty_fipstr)==5
destring statefip, replace

local vars avggrantschaidall avgaid030 avgaid3048 avgnetpriceall avgnp030 avgnp3048 tuitandfee
foreach x of local vars{
gen ln`x' = ln(`x')
}

local vars tuitandfee avggrantschaidall avgnetpriceall avgaid030 avgaid3048 avgnp030 avgnp3048  
foreach x of local vars{

reghdfe ln`x' hasnormalschool, absorb(statefip) cluster(statefip)
outreg2 using instchars.xls, excel append dec(3)

#delimit ;
tabout hasnormalschool if hasnormalorasylum==1 & e(sample)==1 using sumstats_instchars.xls,
append c(mean `x' sd `x') npos(row) f(2)  layout(row) sum show(none); 
#delimit cr
}

restore
